﻿package mortal.game.view.lookPlayerInfo.view
{
    import Message.DB.Tables.*;
    import Message.Game.*;
    import Message.Public.*;
    import baseEngine.modifiers.*;
    import com.gengine.core.frame.*;
    import com.gengine.global.*;
    import com.gengine.resource.*;
    import com.greensock.layout.*;
    import com.mui.controls.*;
    import com.mui.core.*;
    import com.mui.manager.*;
    import com.mui.utils.*;
    import extend.language.*;
    import flash.events.*;
    import flash.geom.*;
    import frEngine.effectEditTool.temple.*;
    import frEngine.pools.*;
    import frEngine.primitives.object2d.*;
    import mortal.common.*;
    import mortal.common.display.*;
    import mortal.common.global.*;
    import mortal.component.gconst.*;
    import mortal.component.window.*;
    import mortal.game.manager.window3d.*;
    import mortal.game.resource.*;
    import mortal.game.resource.info.item.*;
    import mortal.game.resource.tableConfig.*;
    import mortal.game.scene3D.model.data.*;
    import mortal.game.scene3D.model.player.*;
    import mortal.game.scene3D.model.pools.*;
    import mortal.game.view.common.*;
    import mortal.game.view.common.display.*;
    import mortal.game.view.lookPlayerInfo.*;
    import mortal.game.view.vip.*;

    public class LookSystemBasePanel extends GSprite
    {
        private var _isAutoBuy:Boolean = false;
        protected var _currentIndex:int;
        protected var _startX:Number;
        protected var _endX:Number;
        protected var _rightPart:LookSystemRightPart;
        protected var _equipMentPart:LookSystemEquipPart;
        protected var _skillPart:LookSystemSkillPart;
        private var _mountBg:GImageBitmap;
        private var _autoLevelUpBtn:GLoadingButton;
        private var _nolmalLevelUpBtn:GLoadingButton;
        protected var _leftBtn:GLoadedButton;
        protected var _rightBtn:GLoadedButton;
        private var _autoBuy:GCheckBox;
        private var _name:GTextFiled;
        protected var _currLevel:BitmapNumberText;
        protected var _nextLevel:BitmapNumberText;
        protected var _advanceLevelSprite:GSprite;
        protected var _adVanceBtnSprite:GSprite;
        private var _vipIcon:GImageBitmap;
        private var _3dRotationSp:GSprite;
        private var _3dRotationBm:GBitmap;
        protected var _window:Window;
        protected var _rect3d:Rect3DObject;
        protected var _bodyPlayer:ActionPlayer;
        protected var _img2d:Img2D;
        protected var _effectPlayer:EffectPlayer;
        protected var _tmountInfo:TMountConfig;
        private var _frameTimer:FrameTimer;
        protected var _slookPlayerMountInfo:SLookPlayerMountInfo;
        protected var _sLookPlayerInfo:SLookPlayerInfo;
        protected var _lookType:int;
        protected var turnValue:int;

        public function LookSystemBasePanel(param1:Window)
        {
            this._window = param1;
            return;
        }// end function

        public function set window(param1:Window) : void
        {
            var _loc_3:ToolTipSprite = null;
            this._window = param1;
            this._3dRotationSp = UICompomentPool.getUICompoment(GSprite);
            this._3dRotationSp.x = 18;
            this._3dRotationSp.y = 35;
            this._3dRotationSp.mouseEnabled = true;
            this._window.contentTopOf3DSprite.addChild(this._3dRotationSp);
            this._3dRotationBm = GlobalClass.getBitmap(BitmapDataConst.AlphaBMD);
            this._3dRotationBm.width = 485;
            this._3dRotationBm.height = 440;
            this._3dRotationSp.addChild(this._3dRotationBm);
            this._mountBg = UIFactory.gImageBitmap("", 14, 35, this);
            pushUIToDisposeVec(UIFactory.gImageBitmap(ImagesConst.mountTitleBg, 7, 33, this._window.contentTopOf3DSprite));
            var _loc_2:* = GlobalStyle.textFormatBai;
            _loc_2.size = 16;
            _loc_2.align = AlignMode.CENTER;
            this._name = UIFactory.gTextField("", 208 - 83 + 5, 42 - 2, 243, 30, this._window.contentTopOf3DSprite, _loc_2);
            _loc_3 = UICompomentPool.getUICompoment(ToolTipSprite);
            _loc_3.x = 35;
            _loc_3.y = 80;
            _loc_3.toolTipData = this.getVipToolTip;
            this._window.contentTopOf3DSprite.addChild(_loc_3);
            this.pushUIToDisposeVec(_loc_3);
            this._vipIcon = UIFactory.gImageBitmap("", 0, 0, _loc_3);
            this._rightPart = UICompomentPool.getUICompoment(LookSystemRightPart);
            this._rightPart.x = 504;
            this._rightPart.y = 37;
            this._window.contentTopOf3DSprite.addChild(this._rightPart);
            this.addEquipMendtPart();
            this._leftBtn = UIFactory.gLoadedButton(ImagesConst.TurnLeft2_upSkin, 332, 220, 40, 36, this._equipMentPart);
            this._leftBtn.configEventListener(MouseEvent.MOUSE_DOWN, this.onClickTurnBtn);
            this._rightBtn = UIFactory.gLoadedButton(ImagesConst.TurnRight2_upSkin, 91, 220, 40, 36, this._equipMentPart);
            this._rightBtn.configEventListener(MouseEvent.MOUSE_DOWN, this.onClickTurnBtn);
            Global.stage.addEventListener(MouseEvent.MOUSE_UP, this.stopTurning);
            this.addSkillPark();
            this._advanceLevelSprite = UICompomentPool.getUICompoment(GSprite);
            this._advanceLevelSprite.x = 35;
            this._advanceLevelSprite.y = 473;
            this._rightPart.addChild(this._advanceLevelSprite);
            pushUIToDisposeVec(UIFactory.gImageBitmap(ImagesConst.SystemAdvanceBg, 20, -123, this._advanceLevelSprite));
            pushUIToDisposeVec(UIFactory.gImageBitmap(ImagesConst.SystemAdvanceBg, 115, -123, this._advanceLevelSprite));
            pushUIToDisposeVec(UIFactory.gImageBitmap(ImagesConst.SystemAdvanceArrow, 68, -116, this._advanceLevelSprite));
            this._currLevel = UIFactory.bitmapNumberText(41, -116, "GuildNewBuildingNum2.png", 21, 24, -10, this._advanceLevelSprite, 13, 1);
            this._nextLevel = UIFactory.bitmapNumberText(137, -116, "GuildNewBuildingNum2.png", 21, 24, -10, this._advanceLevelSprite, 13, 1);
            this._adVanceBtnSprite = UICompomentPool.getUICompoment(GSprite);
            this._adVanceBtnSprite.x = 35;
            this._adVanceBtnSprite.y = 473;
            var _loc_4:Boolean = false;
            this._adVanceBtnSprite.mouseEnabled = false;
            this._adVanceBtnSprite.mouseChildren = _loc_4;
            this._rightPart.addChild(this._adVanceBtnSprite);
            this._nolmalLevelUpBtn = UIFactory.gLoadingButton(ResFileConst.SystemAdvanceBtn, -17, 1, 114, 33, this._adVanceBtnSprite);
            this._nolmalLevelUpBtn.drawNow();
            this._nolmalLevelUpBtn.filterEnabled = false;
            this._autoLevelUpBtn = UIFactory.gLoadingButton(ResFileConst.SystemAutoAdvanceBtn, 94, 1, 114, 33, this._adVanceBtnSprite);
            this._autoLevelUpBtn.drawNow();
            this._autoLevelUpBtn.visible = true;
            this._autoLevelUpBtn.filterEnabled = false;
            this._autoBuy = UIFactory.checkBox(Language.getString(35335), 24, 43, 210, 28, this._adVanceBtnSprite);
            return;
        }// end function

        override protected function createDisposedChildrenImpl() : void
        {
            super.createDisposedChildrenImpl();
            return;
        }// end function

        override protected function disposeImpl(param1:Boolean = true) : void
        {
            this._skillPart.dispose(param1);
            this._skillPart = null;
            this._mountBg.dispose(param1);
            this._mountBg = null;
            this._name.dispose(param1);
            this._name = null;
            this._vipIcon.dispose(param1);
            this._vipIcon = null;
            this._3dRotationBm.dispose(param1);
            this._3dRotationBm = null;
            this._3dRotationSp.dispose(param1);
            this._3dRotationSp = null;
            this._equipMentPart.dispose(param1);
            this._equipMentPart = null;
            this._rightPart.dispose(param1);
            this._rightPart = null;
            this._nolmalLevelUpBtn.dispose(param1);
            this._nolmalLevelUpBtn = null;
            this._autoLevelUpBtn.dispose(param1);
            this._autoLevelUpBtn = null;
            this._autoBuy.dispose(param1);
            this._autoBuy = null;
            this._advanceLevelSprite.dispose(param1);
            this._advanceLevelSprite = null;
            this._currLevel.dispose();
            this._currLevel = null;
            this._nextLevel.dispose();
            this._nextLevel = null;
            this._leftBtn.dispose(param1);
            this._leftBtn = null;
            this._rightBtn.dispose(param1);
            this._rightBtn = null;
            this._adVanceBtnSprite.dispose(param1);
            this._adVanceBtnSprite = null;
            if (this._effectPlayer)
            {
                this._effectPlayer.dispose(param1);
                this._effectPlayer = null;
            }
            if (this._rect3d)
            {
                if (this._bodyPlayer)
                {
                    this._rect3d.disposeObj3d(this._bodyPlayer);
                    this._bodyPlayer = null;
                }
                if (this._img2d)
                {
                    this._img2d.dispose(param1);
                    this._img2d = null;
                }
                Rect3DManager.instance.disposeRect3d(this._rect3d);
                this._rect3d = null;
            }
            Global.stage.removeEventListener(MouseEvent.MOUSE_UP, this.stopTurn);
            Global.stage.removeEventListener(MouseEvent.MOUSE_DOWN, this.startTurn);
            this.stopTurning();
            Global.stage.removeEventListener(MouseEvent.MOUSE_UP, this.stopTurning);
            this._tmountInfo = null;
            this._slookPlayerMountInfo = null;
            this._sLookPlayerInfo = null;
            super.disposeImpl(param1);
            return;
        }// end function

        protected function addEquipMendtPart() : void
        {
            this._equipMentPart = UICompomentPool.getUICompoment(LookSystemEquipPart);
            this._equipMentPart.x = 20;
            this._equipMentPart.y = 195;
            this._equipMentPart.alpha = 1;
            this._window.contentTopOf3DSprite.addChild(this._equipMentPart);
            return;
        }// end function

        protected function addSkillPark() : void
        {
            this._skillPart = UICompomentPool.getUICompoment(LookSystemSkillPart);
            this._skillPart.x = 20;
            this._skillPart.y = 493;
            this._window.contentTopOf3DSprite.addChild(this._skillPart);
            return;
        }// end function

        protected function onClickTurnBtn(event:MouseEvent) : void
        {
            if (this._bodyPlayer)
            {
                if (event.currentTarget == this._leftBtn)
                {
                    this.turnValue = 2;
                }
                if (event.currentTarget == this._rightBtn)
                {
                    this.turnValue = -2;
                }
                this.start();
            }
            return;
        }// end function

        protected function stopTurning(event:MouseEvent = null) : void
        {
            if (this._frameTimer)
            {
                this._frameTimer.stop();
            }
            return;
        }// end function

        protected function onTurning(param1:FrameTimer) : void
        {
            if (this._bodyPlayer)
            {
                this._bodyPlayer.rotationY = this._bodyPlayer.rotationY + this.turnValue;
            }
            return;
        }// end function

        protected function start() : void
        {
            if (!this._frameTimer)
            {
                this._frameTimer = new FrameTimer(1, int.MAX_VALUE, true);
                this._frameTimer.addListener(TimerType.ENTERFRAME, this.onTurning);
            }
            this._frameTimer.start();
            return;
        }// end function

        private function startTurn(event:MouseEvent) : void
        {
            this._startX = this.mouseX;
            this._3dRotationSp.configEventListener(MouseEvent.MOUSE_MOVE, this.turning);
            return;
        }// end function

        private function stopTurn(event:MouseEvent) : void
        {
            this._3dRotationSp.removeEventListener(MouseEvent.MOUSE_MOVE, this.turning);
            return;
        }// end function

        protected function turning(event:MouseEvent) : void
        {
            this._endX = this.mouseX;
            if (this._bodyPlayer)
            {
                this._bodyPlayer.rotationY = this._bodyPlayer.rotationY - (this._endX - this._startX) / 3;
            }
            this._startX = this._endX;
            return;
        }// end function

        protected function add2d() : void
        {
            if (this.isDisposed)
            {
                return;
            }
            this.add3d();
            this.update3DModel();
            this._img2d = new Img2D(null, this._mountBg.bitmapData, new Rectangle(0, 0, 490, 546), false);
            this._rect3d.addImg(this._img2d);
            Global.stage.addEventListener(MouseEvent.MOUSE_DOWN, this.startTurn);
            Global.stage.addEventListener(MouseEvent.MOUSE_UP, this.stopTurn);
            return;
        }// end function

        protected function add3d() : void
        {
            if (!this._rect3d)
            {
                this._rect3d = Rect3DManager.instance.registerWindow(true, new Rectangle(11, 38, 490, 546), this._window);
            }
            Rect3DManager.instance.windowShowHander(null, this._window);
            return;
        }// end function

        protected function update3DModel() : void
        {
            var _loc_1:int = 0;
            var _loc_2:TModel = null;
            var _loc_3:String = null;
            var _loc_4:String = null;
            if (this._rect3d && this._tmountInfo)
            {
                if (this._slookPlayerMountInfo.shape > 10)
                {
                    _loc_1 = (ItemConfig.instance.getConfig(this._slookPlayerMountInfo.shape) as ItemEquipInfo).modelId;
                }
                else
                {
                    _loc_1 = this._tmountInfo.modelId;
                }
                _loc_2 = ModelConfig.instance.getInfoByCode(_loc_1);
                _loc_3 = _loc_2.mesh1 + ".md5mesh";
                _loc_4 = _loc_2.bone1 + ".skeleton";
                if (this._bodyPlayer == null)
                {
                    this._bodyPlayer = FrObjectPool.getObject(ActionPlayer, this);
                }
                if (this._bodyPlayer.meshUrl != _loc_3 || this._bodyPlayer.animUrl != _loc_4)
                {
                    this._bodyPlayer.load(_loc_3, _loc_4, _loc_2.texture1, this._rect3d.renderList);
                }
                this._bodyPlayer.changeAction(ActionName.MountStand);
                this._bodyPlayer.alpha = 1;
                this._bodyPlayer.play();
                this.reset3dModelPos(_loc_2);
                if (VipConfig.instance.isShowEffect(LookPlayerUtil.getVipRecordTypeByLookType(this._lookType).type, this._sLookPlayerInfo.miniPlayer.VIP))
                {
                    if (this._effectPlayer)
                    {
                        this._effectPlayer.dispose(true);
                        this._effectPlayer = null;
                    }
                    if (_loc_2.effect1)
                    {
                        this._effectPlayer = EffectPlayerPool.instance.getEffectPlayer(_loc_2.effect1, this._bodyPlayer, this._rect3d.renderList, false);
                        if (this._effectPlayer.temple is TempleRole)
                        {
                            (this._effectPlayer.temple as TempleRole).setRoleParams(this._bodyPlayer, null, null);
                        }
                        this._effectPlayer.play(PlayMode.ANIMATION_LOOP_MODE);
                    }
                }
            }
            return;
        }// end function

        protected function reset3dModelPos(param1:TModel = null) : void
        {
            var _loc_2:int = 0;
            var _loc_3:int = 0;
            if (this._lookType == ELookUpType._ELookUpTypeMount)
            {
                if (this._currentIndex == 10)
                {
                    this._bodyPlayer.rotationY = 0;
                }
                else
                {
                    this._bodyPlayer.rotationY = 50;
                }
                this._bodyPlayer.scaleValue = 1.3;
                _loc_2 = 245;
                _loc_3 = 375;
            }
            else
            {
                this._bodyPlayer.rotationY = 0;
                this._bodyPlayer.scaleValue = 1.3;
                _loc_2 = 245;
                _loc_3 = 375;
            }
            this._rect3d.addObject3d(this._bodyPlayer, _loc_2, _loc_3);
            return;
        }// end function

        protected function getVipToolTip() : String
        {
            var _loc_2:String = null;
            var _loc_3:int = 0;
            var _loc_4:TVip = null;
            var _loc_5:int = 0;
            var _loc_6:String = null;
            var _loc_1:* = LookPlayerUtil.getVipRecordTypeByLookType(this._lookType);
            if (_loc_1)
            {
                _loc_3 = _loc_1.type;
                _loc_4 = VipConfig.instance.getVipConfigByType(_loc_3);
                _loc_5 = VipUtil.getVipMinLevelByType(_loc_3);
                _loc_6 = _loc_1.name;
                if (_loc_4)
                {
                    _loc_2 = Language.getStringByParam(35336, _loc_5, _loc_6, _loc_6, _loc_4.desc);
                }
            }
            return _loc_2;
        }// end function

        protected function updateVip() : void
        {
            var _loc_1:* = this._sLookPlayerInfo.miniPlayer.VIP;
            var _loc_2:* = LookPlayerUtil.getVipRecordTypeByLookType(this._lookType).type;
            var _loc_3:* = VipConfig.instance.getValueByTypeAndLv(_loc_2, _loc_1);
            var _loc_4:* = VipUtil.getVipMinLevelByType(_loc_2);
            if (_loc_1 >= _loc_4)
            {
                this._vipIcon.filters = [];
                this._vipIcon.imgUrl = GameDefConfig.instance.getVipLevelIconUrl(_loc_1, 2);
            }
            else
            {
                this._vipIcon.filters = [FilterConst.colorFilter2];
                this._vipIcon.imgUrl = GameDefConfig.instance.getVipLevelIconUrl(_loc_4, 2);
            }
            return;
        }// end function

        protected function updatePageBtn() : void
        {
            return;
        }// end function

        protected function updateMountInfo() : void
        {
            this._tmountInfo = MountConfig.instance.getMountInfoByCode(this._currentIndex, LookPlayerUtil.getConfigTypeByLookType(this._lookType));
            this._name.text = this._tmountInfo.name;
            this.update3DModel();
            this.updatePageBtn();
            return;
        }// end function

        protected function addOtherObj() : void
        {
            pushUIToDisposeVec(UIFactory.gImageBitmap(ImagesConst.mountText_6, -366 + this._rightPart.x, 45 + this._rightPart.y, this._window.contentTopOf3DSprite));
            var _loc_1:* = GlobalStyle.textFormatLv.left();
            _loc_1.size = 12;
            this.pushUIToDisposeVec(UIFactory.gTextField(Language.getStringByParam(30318, this._tmountInfo.addSpeed), -250 + this._rightPart.x, 45 + this._rightPart.y, 200, 25, this._window.contentTopOf3DSprite, _loc_1));
            this.pushUIToDisposeVec(UIFactory.gTextField(Language.getStringByParam(30319, this._tmountInfo.speed), -250 + this._rightPart.x, 63 + this._rightPart.y, 200, 25, this._window.contentTopOf3DSprite, _loc_1));
            return;
        }// end function

        public function setLookInfo(param1:SLookPlayerMountInfo, param2:SLookPlayerInfo, param3:int) : void
        {
            this._slookPlayerMountInfo = param1;
            this._sLookPlayerInfo = param2;
            this._lookType = param3;
            if (this._slookPlayerMountInfo.code <= 0)
            {
                this._slookPlayerMountInfo.code = 1;
            }
            var _loc_4:* = LookPlayerUtil.getConfigTypeByLookType(this._lookType);
            this._tmountInfo = MountConfig.instance.getMountInfoByCode(this._slookPlayerMountInfo.code, LookPlayerUtil.getConfigTypeByLookType(this._lookType));
            this._equipMentPart.setLookInfo(this._slookPlayerMountInfo, this._lookType);
            this._rightPart.setLookInfo(this._sLookPlayerInfo, this._slookPlayerMountInfo, this._lookType);
            this._skillPart.setLookInfo(this._slookPlayerMountInfo, this._lookType);
            this._currentIndex = this._tmountInfo.code;
            if (this._slookPlayerMountInfo.code < 10)
            {
                this._currLevel.text = "" + this._slookPlayerMountInfo.code;
                this._nextLevel.text = (this._slookPlayerMountInfo.code + 1) + "";
                this._advanceLevelSprite.visible = true;
            }
            else
            {
                this._advanceLevelSprite.visible = false;
            }
            this.updateMountInfo();
            this.updateVip();
            this.addOtherObj();
            LoaderHelp.setBitmapdata(LookPlayerUtil.getLeftBgUrlByLookType(this._lookType), this._mountBg, 0, 0, -1, -1, this.add2d);
            return;
        }// end function

    }
}
